package com.gipson.amc.utils.strprocess;

/**
 * @author cjw 2019-10-21
 */
public class RandomStrUtil {

	/**
	 * 返回《0, range-1》范围内的整数。
	 *
	 * @return
	 */
	public static int getNum(int range) {

		int result = 0;
		result = (int) (Math.random() * range);
		return result;
	}

	/**
	 * 随机返回count位数字，数字范围为：0-9。
	 *
	 * @return
	 */
	public static String getNumStr(int count) {
		String chars = "0123456789";
		String result = "";

		for (int i = 0; i < count; i++) {
			result = result + chars.charAt(getNum(10));
		}
		return result;
	}

	/**
	 * 随机返回4个字符，字符范围为：a-z,A-Z,0-9。
	 * @param
	 * @return
	 * @author cjw 2020-04-10
	 */
	public static String getRandomStr() {
		String chars = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789";
		String result = null;
		result = "" + chars.charAt(getNum(62)) + chars.charAt(getNum(62)) + chars.charAt(getNum(62)) + chars.charAt(getNum(62));
		return result;
	}


}
